<?php


namespace app\api\model;

use app\api\controller\Code;
use think\Db;
use think\Model;

/**
 * 用户信息
 * Class UserModel
 * @package app\api\model
 *
 */
class UserModel extends Model
{

    /**
     * 设置表名
     * @var string
     */
    protected $table = 'ah_user';

    /**
     *
     * 查询个人用户信息
     */
    public static function userInfo($where = [],$field = '*'){

        return self::where($where)->field($field)->find();
    }

    /**
     *
     * 修改用户信息
     */
    public static function userEdit($params){

        Db::startTrans();
        if (isset($params['id'])){

            $params['update_at'] = time();
            $res1 = self::where(['id'=>$params['id']])->update($params);
            $res2 = TengXunModel::tengXunIMAdd($params);
        }else{

            $res1 = self::insertGetId($params);
            $res2 = TengXunModel::tengXunIMAdd(['id'=>$res1]);

        }
        if ($res1 && $res2){

            Db::commit();
            return true;
        }else{

            Db::rollback();
            return false;
        }

    }

    /**
     *
     * 专家接口
     */
    public static function expertList(){

        return self::where(['type'=>1])->field('id,head_img,phone,nickname,hospital_name,self_info')->select();
    }



}